package com.tanhua.dubbo.api;

import com.tanhua.domain.mongo.RecommendUser;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

@Service
public class RecommendUserApiImpl implements RecommendUserApi {
    @Autowired
    private MongoTemplate mongoTemplate;

    /**
     * 查询佳人
     * @param userId
     * @return
     */
    @Override
    public RecommendUser findRecommendUserId(Long userId) {
        Query query = new Query();
        query.addCriteria(Criteria.where("toUserId").is(userId));
        query.with(Sort.by(Sort.Order.desc("score")));
        RecommendUser recommendUser = mongoTemplate.findOne(query, RecommendUser.class);
        return recommendUser;
    }
}
